<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
      <el-breadcrumb-item :to="{ path: '/sys-admin' }">
        <i class="el-icon-s-promotion"></i> 后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>留言列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-divider></el-divider>

    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" align="center" width="100"></el-table-column>
      <el-table-column prop="addtime" label="发布时间" align="center" width="200"></el-table-column>
      <el-table-column prop="content" label="留言" align="center" width="250"></el-table-column>
      <el-table-column prop="userid" label="用户人id" align="center" width="150"></el-table-column>
      <el-table-column label="操作" align="center" width="150">
        <template slot-scope="scope">
          <el-button type="danger" icon="el-icon-delete" size="mini" circle
                     @click="openDeleteConfirm(scope.row)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: []
    }
  },
  methods: {
    changeEnable(messages) {
      console.log('changeEnable ...');
      console.log(messages);
      if (messages.enable == 1) {
        console.log('将向服务器端提交请求：启用管理员');
      } else {
        console.log('将向服务器端提交请求：禁用管理员');
      }
    },
    handleEdit(messages) {

    },
    openDeleteConfirm(messages) {
      let title = '提示';
      let message = '此操作将永久删除【' + messages.username + '】管理员，是否继续？';
      this.$confirm(message, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(messages);
      }).catch(() => {
      });
    },
    handleDelete(messages) {
      console.log('handleDelete ... id=' + messages.id);
      let url = 'http://localhost:8090/messages/' + messages.id + '/delete';
      console.log('url = ' + url);
      this.axios.post(url).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        if (responseBody.state != 20000) {
          this.$message.error(responseBody.message);
        }
        this.loadAdminList();
      });
    },
    loadAdminList() {
      console.log('loadAdminList ...');
      let url = 'http://localhost:8090/messages/';
      console.log('url = ' + url);
      this.axios.get(url).then((response) => {
        let responseBody = response.data;
        console.log(responseBody);
        this.tableData = responseBody.data;
      });

    }
  },
  mounted() {
    this.loadAdminList();
  }
}
</script>
<style scoped>

</style>